package dao;

import java.util.LinkedList;
import java.util.List;
import entities.Group;

public class GroupDAO 
{

	private static final GroupDAO instance = new GroupDAO();
	private List<Group> groups;
	
	private GroupDAO(){
		groups = new LinkedList<Group>();
		Group group = null;
		
		group = Group.newInstance("Rolling Stones", 1L);
		groups.add(group);
	}
	
	public static GroupDAO getInstance() {
		return instance;
	}

	public synchronized Group findGroup(Long a_id) {
		Group result = null;
		for (Group s : groups){
			if (s.getA_id().equals(a_id)){
				result = s;
			}
		}
		return result;
	}

	public synchronized void addGroup(Group obj) throws RecordDuplicateException{
		if (findGroup(obj.getA_id()) != null){
			throw new RecordDuplicateException("Customer with id: " + obj.getA_id() + " is already in the db.");
		}
		else {
			groups.add(obj);
		}
	}
}
